package grammer.phrase;

import grammer.DirectObject;
import grammer.LocalObject;
import grammer.Member;
import grammer.ModalObject;
import grammer.Predicate;
import grammer.Subject;
import grammer.TimeObject;
import grammer.WeatherSubject;

import java.util.Vector;

public class Phrase {
	private boolean isWeather;
	private Vector<Member> parts;

	Phrase() {
		parts = new Vector<Member>();
		isWeather = false;
	}

	public void add(Member m) {
		parts.add(m);
	}

	public Member get(int i) {
		return parts.get(i);
	}

	public int getCount() {
		return parts.size();
	}

	public DirectObject getDirectObject() {
		for (int i = 0; i < parts.size(); i++)
			if (parts.get(i) instanceof DirectObject)
				return (DirectObject) parts.get(i);
		return null;
	}

	public LocalObject getLocalObject() {
		for (int i = 0; i < parts.size(); i++)
			if (parts.get(i) instanceof LocalObject)
				return (LocalObject) parts.get(i);
		return null;
	}

	public ModalObject getModalObject() {
		for (int i = 0; i < parts.size(); i++)
			if (parts.get(i) instanceof ModalObject)
				return (ModalObject) parts.get(i);
		return null;
	}

	public Predicate getPredicate() {
		for (int i = 0; i < parts.size(); i++)
			if (parts.get(i) instanceof Predicate)
				return (Predicate) parts.get(i);
		return null;
	}

	public Subject getSubject() {
		for (int i = 0; i < parts.size(); i++)
			if (parts.get(i) instanceof Subject)
				return (Subject) parts.get(i);
		return null;
	}

	public TimeObject getTime() {
		for (int i = 0; i < parts.size(); i++)
			if (parts.get(i) instanceof TimeObject)
				return (TimeObject) parts.get(i);
		return null;
	}

	public WeatherSubject getWeather() {
		for (int i = 0; i < parts.size(); i++)
			if (parts.get(i) instanceof WeatherSubject)
				return (WeatherSubject) parts.get(i);
		return null;
	}

	public boolean isWeather() {
		return isWeather;
	}

	public void setWeather(boolean b) {
		this.isWeather = b;
	}

	@Override
	public String toString() {
		String result = new String();
		for (int i = 0; i < parts.size(); i++) {
			result = result + " " + parts.get(i).getMember().toString();
		}
		return result;
	}

}
